import { Component } from 'react'
import { View, Text } from '@tarojs/components'
import Taro from "@tarojs/taro"

import './redirect.scss'
import {redirectUrl} from "./onShareAppMessage";

export default class Redirect extends Component {

  componentWillMount () {
    const instance = Taro.getCurrentInstance();
    const Home = "/pages/index/index";
    if (instance.router?.params.hasOwnProperty(redirectUrl)) {
      const path = decodeURIComponent(instance.router?.params[redirectUrl]!);
      Taro.redirectTo({url: path}).catch(_ => {
        return Taro.redirectTo({url:Home})
      });
      return ;
    }

    Taro.redirectTo({url:Home}).then();
  }

  componentDidMount () {}

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }

  render () {
    return (
      <View className='index'>
        <Text>跳转中</Text>
      </View>
    )
  }
}
